package com.xiaolin.spring.annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName ADemoTest
 * @Description TODO
 * @Detail 基于注解的配置
 * @Author MyPC
 * @Date 2020/10/27
 * @Version 1.0
 */
public class ADemoTest2 {

    private ABean aBean;
    private BBean bBean;

    //作用在属性上
    @Autowired
    private CBean cBean;
    //作用在数组上，会注入一个实例到数组中
    @Autowired
    private CBean[] cBeans;
    //作用在list集合上，会注入一个实例到数组中
    @Autowired
    private List<CBean> cBeanList;
    //作用在set集合上，会注入一个实例到数组中
    @Autowired
    private Set<CBean> cBeanSet;
    //作用在map集合上，会注入一个实例到数组中
    @Autowired
    private Map<String,CBean> cBeanMap;

    /**
     * 作用普通方法上，可以注入多个参数
     * @param aBean
     * @param bBean
     */
    @Autowired
    public void au(ABean aBean,BBean bBean){
        this.aBean=aBean;
        this.bBean=bBean;
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("a-demo-test.xml");
        ADemoTest2 ad = applicationContext.getBean("ad2", ADemoTest2.class);
        System.out.println(ad.aBean);
        System.out.println(ad.bBean);
        System.out.println(ad.cBean);
        System.out.println(ad.cBeans[0]);
        System.out.println(ad.cBeanList.size());
        System.out.println(ad.cBeanSet.size());
        System.out.println(ad.cBeanMap.size());
    }
}
